﻿
@{
    ViewBag.Title = "等级颜色配置-颜色";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
}

<div id="page"></div>

<script type="text/template" id="tplPage">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">组件颜色：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="txtKey" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>

                    <div class="layui-inline">
                        <label class="layui-form-label">代码:</label>
                        <div class="layui-input-inline">
                            <input type="text" id="txtKey" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button id="btnSearch" class="layui-btn layuiadmin-btn-list" type="button">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                        <button class="layui-btn layui-btn-normal layuiadmin-btn-list" type="button" onclick="editRole(0);">
                            <i class="layui-icon layui-icon-addition layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-card">
            <div class="layui-card-body">
                <table id="table" lay-filter="table"></table>
            </div>
        </div>
    </div>
</script>

@section Scripts{
    <script>
        var orderNo = "@ViewBag.OrderNo",
            workOrderNo = "@ViewBag.WorkOrderNo";
        var vm = new Vue({
            el: "#page",
            template: "#tplPage",
            data: {
                lang: JSON.parse(lang).package
            }
        });
        setTimeout(function () {
            initLayui();
        }, 50);
            function initLayui() {
                layui.use(['table', 'layer'], function () {
                    var layer = layui.layer,
                        table = layui.table;

                    var options = {
                        elem: '#table'
                        , url: '/ParaSetting/QueryColorSets'
                        , method: "post"
                        , where: { compColor: '', compColorCode: '' }
                        , page: {
                            limit: 15
                            , limits: [15, 20, 25, 30, 40, 50]
                        }
                        , response: {
                            statusName: 'ErrCode'
                            , statusCode: 200
                            , msgName: 'ErrCode'
                            , countName: 'TotalCount'
                            , dataName: 'Data'
                        }
                        , cols: [[
                            { field: 'PkId', title: 'ID', width: 60 }
                            , { field: 'CompColor', title: '组件颜色' }
                            , { field: 'CompColorCode', title: '组件颜色代码' }
                            , {
                                title: '操作', width: 200, templet: function (d) {
                                    var str = '<button class="layui-btn layui-btn-sm layui-btn-normal" onclick="editRole(' + d.PkId + ')"><i class="layui-icon">&#xe642;</i>编辑</button>\
                                                                                           <button class="layui-btn layui-btn-sm layui-btn-danger" onclick="deleteRole(' + d.PkId + ',\'' + d.CompColor + '\')"><i class="layui-icon">&#xe640;</i>删除</button>';
                                    return str;
                                }
                            }
                        ]]
                    };

                    $("#btnSearch").click(function () {
                        queryTable();
                    });
                    queryTable();
                    function queryTable() {
                        options.page.curr = 1;
                        if (table.index <= 0) {
                            table.render(options);
                        } else {
                            table.reload("table", options);
                        }
                    }
                });
            }

            function editRole(roleId) {
                layer.open({
                    type: 2,
                    shade: [0.1, '#000'],
                    area: ['550px', '300px'],
                    content: "/ParaSetting/ColorSetEdit?pkId=" + roleId,
                    end: function () {
                        $("#btnSearch").click();
                    }
                });
            }

            function deleteRole(roleId, roleName) {
                layer.confirm('确定要删除“' + roleName + '”吗？', { icon: 3, title: '提示' }, function (index) {
                    var loadId = layer.load();
                    $.ajax({
                        async: false,
                        url: "/ParaSetting/ColorSetDelete?pkId=" + roleId,
                        complete: function () {
                            layer.close(loadId);
                        },
                        success: function (res) {
                            if (res.ErrCode != 200) {
                                layer.msg(res.ErrMsg, { icon: 5 });
                                return;
                            }
                            layer.msg("删除成功！", { icon: 6, time: 1500 });
                            $("#btnSearch").click();
                        }
                    });
                    layer.close(index);
                });
            }
    </script>
}
